package com.lyl.commonutils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtils {

    public static String formatDate(Date date,int day){
        SimpleDateFormat sdf=new SimpleDateFormat ("yyyy-MM-dd") ;
        Calendar calendar = Calendar . getInstance();
        calendar. setTime(date) ;
        calendar .add (Calendar.DAY_OF_MONTH,day) ;

        date = calendar .getTime() ;
        return   sdf. format(date) ;
    }
    public static String formatDateTime(Date date){
        SimpleDateFormat sdf=new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss") ;
        Calendar calendar = Calendar . getInstance();
        calendar. setTime(date) ;
        date = calendar .getTime() ;
        return   sdf. format(date) ;
    }
    public static String formatDateTimeHm(Date date){
        SimpleDateFormat sdf=new SimpleDateFormat ("HH:mm") ;
        Calendar calendar = Calendar . getInstance();
        calendar. setTime(date) ;
        date = calendar .getTime() ;
        return   sdf. format(date) ;
    }

    public static String formatDate(Date date,int day,int util){
        SimpleDateFormat sdf=new SimpleDateFormat ("yyyy-MM-dd") ;
        Calendar calendar = Calendar . getInstance();
        calendar. setTime(date) ;
        calendar .add (util,day) ;
        date = calendar .getTime() ;
        return   sdf. format(date) ;
    }

    public static int dateCompare(Date curTime, Date startTime) {

            int flagValue = 0;

            // 当前时间- 开始时间
        long millisecond = curTime.getTime() - startTime.getTime() ;
        if (millisecond >0) {
            flagValue = 1;
        } else if (millisecond < 0) {
            flagValue = -1;
        } else if (millisecond == 0) {
            flagValue = 0;
        }
        return flagValue;
    }
}
